﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace CopyIt
{
    public partial class DisplayAll : UserControl
    {
        public event ItemCheckedEventHandler ItemChecked;

        public List<PairsParameters> Params;
        private string[] OverrideMode = new string[] { "Ignora", "Sovrascrivi", "Sovrascrivi se differente", "Sovrascrivi se più nuovo" };

        public DisplayAll()
        {
            
            InitializeComponent();
        }

        public void SetParams(List<PairsParameters> Params)
        {
            ListViewItem lvI;
            ListViewItem.ListViewSubItem lsI;

            this.Params = Params;
            lswPairs.Items.Clear();
            foreach (PairsParameters par in Params)
            {
                lvI = lswPairs.Items.Add("");
                lvI.UseItemStyleForSubItems = false;
                lvI.Checked = par.Checked;
                lsI = lvI.SubItems.Add(par.SourceFolder);
                lsI = lvI.SubItems.Add(par.DestFolder);
                lsI = lvI.SubItems.Add(par.CurrentIncludeFilter);
                lsI.ForeColor = par.EnableIncludeFilter ? Color.Black : Color.LightGray;
                lsI = lvI.SubItems.Add(par.CurrentExcludeFilter);
                lsI.ForeColor = par.EnableIncludeFilter ? Color.Black : Color.LightGray;
                lsI = lvI.SubItems.Add("Escludi sola lettura");
                lsI.ForeColor = (par.ExcludeTypes & System.IO.FileAttributes.ReadOnly) != 0 ? Color.Black : Color.LightGray;
                lsI = lvI.SubItems.Add("Escludi nascosti");
                lsI.ForeColor = (par.ExcludeTypes & System.IO.FileAttributes.Hidden) != 0 ? Color.Black : Color.LightGray;
                lsI = lvI.SubItems.Add("Escludi sistema");
                lsI.ForeColor = (par.ExcludeTypes & System.IO.FileAttributes.System) != 0 ? Color.Black : Color.LightGray;
                lvI.SubItems.Add(OverrideMode[(int)par.Override]);
            }
            foreach (ColumnHeader col in lswPairs.Columns)
                col.Width = -2;
        }

        private void DisplayAll_Paint(object sender, PaintEventArgs e)
        {
            Rectangle TopRect = this.ClientRectangle;
            PointF lF = new PointF(TopRect.Left + 10, 45);
            PointF rF = new PointF(TopRect.Right - 10, 45);

            e.Graphics.DrawLine(new Pen(Color.FromArgb(125, 152, 193)), lF, rF);
        }

        private void lswPairs_ItemChecked(object sender, ItemCheckedEventArgs e)
        {
            if (ItemChecked != null)
                ItemChecked(sender, e);
        }
    }
}
